/**
 * 面试安排外部接口
 */
import request from '@/utils/request';

const getUserCode = () => localStorage.getItem('candidateUserCode') || '';

/**
 * 获取全局状态信息
 */
export async function getTotalInfo(id) {
    return request(`/api/recruitment/public/v1/candidates/${id}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 获取面试安排信息
 */
export async function getInterviewArrange(id) {
    return request(`/api/recruitment/public/v1/candidates/interview_arrange/${id}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 获取公司名称
 */
export async function getInterviewCompanyInfo(interviewNoticeId) {
    return request(`/api/recruitment/public/v1/candidates/company_info/${interviewNoticeId}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 获取面试安排链接是否有效
 */
export async function getInterviewEffective(id) {
    return request(`/api/recruitment/public/v1/candidates/interview_effective/${id}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 接受面试
 * @param {*} params
 */
export async function acceptInterview(id) {
    return request(`/api/recruitment/public/v1/candidates/interview_arrange/${id}/action/receive`, {
        method: 'PUT',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 获取面试官日程
 */
export async function getInterviewRangeMap(interviewNoticeId) {
    return request(`/api/recruitment/public/v1/candidates/list_interviewer_schedule/${interviewNoticeId}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 修改面试时间
 * @param {*} params
 */
export async function changeInterview(params, id) {
    return request(`/api/recruitment/public/v1/candidates/interview_arrange/${id}/action/update_interview_time`, {
        method: 'PUT',
        data: params
    });
}

/**
 * 拒绝面试
 * @param {*} params
 */
export async function refuseInterview(params, id) {
    return request(`/api/recruitment/public/v1/candidates/interview_arrange/${id}/action/refuse`, {
        method: 'PUT',
        data: params,
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 应聘登记表获取声明内容
 */
export async function getDeclare(id) {
    return request(`/api/recruitment/public/v1/candidates/setting_content/${id}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 获取简历详情
 */
export async function getResumeDetail(interviewNoticeId) {
    // /api/oa/v1/work/recruitment/resumes/application_forms/{id}
    // return request(`/api/oa/v1/work/recruitment/resumes/${interviewNoticeId}/personal_detail`, {
    return request(`/api/recruitment/public/v1/resumes/mobile/${interviewNoticeId}/personal_detail`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 *
 * 获取应聘登记表详情
 *
 */
export async function getRegistrationDetail(interviewNoticeId) {
    console.log('getRegistrationDetail-------');
    // /api/oa/v1/work/recruitment/resumes/application_forms/{id}
    // return request(`/api/oa/v1/work/recruitment/resumes/${interviewNoticeId}/personal_detail`, {
    return request(`/api/recruitment/v1/candidates/external/application_forms/${interviewNoticeId}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 更新简历详情
 * @param {*} params
 */
export async function updateResume(params) {
    // return request(`/api/oa/v1/work/recruitment/resumes/standard_resumes/${params.resumeId}`, {
    return request(`/api/recruitment/public/v1/resumes/mobile/candidate_resumes/${params.resumeId}`, {
        method: 'PUT',
        data: params,
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 更新应聘登记表
 * @param {*} params
 */
export async function updateRegistration(params) {
    // return request(`/api/oa/v1/work/recruitment/resumes/standard_resumes/${params.resumeId}`, {
    return request(`/api/recruitment/v1/candidates/external/application_forms/${params?.interviewNoticeId}`, {
        method: 'PUT',
        data: params,
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 更新简历-个人信息
 * @param {*} params
 */
export async function updatePersonalInfo(params) {
    // /api/oa/v1/work/recruitment/auth/candidates/external/application_forms/mobile/${params.id}/actions/update_personal_info
    return request(`/api/recruitment/v1/resumes/${params.id}/actions/update_personal_info`, {
        method: 'PUT',
        data: params,
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 修改密码
 * @param {*} params
 */
export async function updatePassword(params) {
    return request('/api/user/public/v1/account/editPassByCache', {
        method: 'POST',
        data: params,
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 应聘登记表点击完善个人信息
 */
export async function checkLogin(interviewNoticeId) {
    console.log('checkLogin--------', getUserCode(), interviewNoticeId);
    // return request(`/api/oa/v1/work/recruitment/candidates/${interviewNoticeId}/perfect_personal`, {
    return request(`/api/recruitment/public/v1/candidates/${interviewNoticeId}/perfect_personal`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 应聘登记表点击完善个人信息
 */
export async function getLoginInfo(candidateLinkId) {
    // return request(`/api/oa/v1/work/recruitment/candidates/${interviewNoticeId}/perfect_personal`, {
    return request(`/api/recruitment/public/v1/candidates/${candidateLinkId}/login_infos`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

// 登录接口（新）
export async function fakeAccountLogin(params) {
    return request('/api/user/public/v2/account/login', {
        method: 'POST',
        data: params
        // getResponse: true,
        // encryption: true
    });
}

// 发送验证码接口
export async function getVerificationCode(key) {
    return request(`/api/user/public/v2/verification/send?key=${key}`, {
        method: 'GET',
        headers: {
            current_account_user_code: getUserCode()
        }
    });
}

/**
 * 面试签到接口
 */
export async function querySignIn(params) {
    // return request(`/api/oa/v1/work/recruitment/resumes/${interviewNoticeId}/personal_detail`, {
    return request('/api/oa/public/v1/work/recruitment/interviews/actions/sign_in', {
        method: 'POST',
        data: params
    });
}

/**
 * 面试签到获取数据详情
 */
export async function getSignInData(arrangeId) {
    return request(`/api/recruitment/public/v1/interviews/${arrangeId}/sign_in_info`, {
        method: 'GET'
    });
}
/**
 * 提交面试作业
 * @param {object} params
 */
export async function saveWork(params) {
    return request('/api/recruitment/v1/interviews/homework/actions/submit_homework', {
        method: 'POST',
        data: params
    });
}

/*
获取岗位详情和面试题目
*/
export async function getJobAndQuestionInfo(arrangeId) {
    return request(`/api/recruitment/v1/interviews/homework/info_for_submit_homework/${arrangeId}`, {
        method: 'GET'
    });
}

/*
确认候选人账号信息

*/
export async function getCheckAccount(candidateEmail, query) {
    return request('/api/recruitment/public/v1/candidates/temps/actions/check_account', {
        method: 'POST',
        data: {
            ...query,
            candidateEmail
        }
    });
}
